#pragma once
#include "afxdtctl.h"
#include "afxwin.h"
#include "afxcmn.h"
#include "TimeZone.h"

#include "../_inc/TimeList.h"
#include "../_inc_app/IIntrBackup2.h"


enum _BackupType
{
	Backup_Avi = 0,
	Backup_Img,
	Backup_type_count
};

// CDlgBackup dialog
class CWndListTime;
class CWndListEvent;
class CDlgViewerBG;
class CDlgBackup : public CDialog
{
	DECLARE_DYNAMIC(CDlgBackup)

private:
	IIntrBackup2	*m_pIntrBackup2;
	CDlgViewerBG	*m_pViewerSetup;

	TCHAR			m_tzBackupPath[MAX_PATH];
	TCHAR			m_tzDbPath[MAX_REC_TYPE][MAX_PATH];

	time_t			m_dwBackupStartTime;
	time_t			m_dwBackupEndTime;

	int				m_nUpdateID;

	CWndListTime	*m_pWndListTime;
	CWndListEvent	*m_pWndListEvent;
	CTimeZone		m_TimeZone;

	CTimeList		m_tCurList;
	DWORD			m_dwRecType;

	int				m_nStartIndex;

	ST_FILE_NAME_FORMAT		m_stAVIFileNameFormat;

	BYTE *m_pImageData[MAX_CHANNEL];
	int m_nWidth[MAX_CHANNEL];
	int m_nHeight[MAX_CHANNEL];
	int m_nFormat[MAX_CHANNEL];
	time_t m_tSaveTime[MAX_CHANNEL];
	

protected:
	static void _CallbackBackup(UINT nCmd, DWORD wParam, void* lParam, void* pApp);
	void CallbackBackup(UINT nCmd, DWORD wParam, void* lParam);

public:
	CDlgBackup(CWnd* pParent = NULL);   // standard constructor
	virtual ~CDlgBackup();

private:
	void UpdateControlData();
	void UpdateControl();
	void UpdateSetting();

	void LoadText();

public:
	TCHAR* GetBackupPath();
	void SetBackupPath(TCHAR* tzPath);
	void SetDbPath(DWORD dwRecType, TCHAR* tzPath);
	void SetBackupStartTime(DWORD dwStartTime);
	void SetBackupStartIndex(int nStartIndex, SEARCH_TYPE nSearchType);
	void SetTimeListObject(CWndListTime *pWndListTime);
	void SetEventListObject(CWndListEvent *pWndListEvent);

	BOOL IsSelCamera(int nCam);	

	void SetProgressPos(int nPos, DWORD dwBackupTime);
	void SetFinBackup(BOOL bResult);
	void SetRecMode(int nRecMode) { m_nRecMode = nRecMode; };
	void SetAVIFileNameFormat(ST_FILE_NAME_FORMAT stFmt) { m_stAVIFileNameFormat = stFmt; };

	void SetCurrentImage(int nChannel, BYTE *pImage, int nWidth, int nHeight, int nFormat, time_t tSaveTime);

	void RefreshLang();
	void SetViewerSetup(CDlgViewerBG *pViewerSetup) { m_pViewerSetup = pViewerSetup; };

// Dialog Data
	enum { IDD = IDD_BACKUP };

public:
	afx_msg void OnDestroy();
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnInitDialog();
	afx_msg void OnBnClickedRadioBackupType(UINT nID);
	afx_msg void OnBnClickedCheckBackupCam();
	afx_msg void OnBnClickedBtnBackupPath();
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedCancel();
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnDtnDatetimechangeDatetimepickerStart(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDtnDatetimechangeDatetimepickerEnd(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedBtnStop();
	afx_msg void OnBnClickedButtonOpenFolder();
	DECLARE_MESSAGE_MAP()

private:
	int m_nBackupType;

	CDateTimeCtrl m_dtpStart;
	CDateTimeCtrl m_dtpEnd;
	
	BOOL m_bSelCam1;
	BOOL m_bSelCam2;
	BOOL m_bSelCam3;
	BOOL m_bSelCam4;

	BOOL m_bSelCam[MAX_CHANNEL];

	CStatic m_txtBackupPath;

	CProgressCtrl m_pgrBackup;
	
	CStatic m_txtBackupStart;
	CStatic m_txtBackupEnd;
	
	CButton m_btnBackupStart;
	CButton m_btnClose;
	CButton m_btnStop;

	SEARCH_TYPE m_nSearchType;
	int m_nBackupMode;
	int m_nRecMode;
	BOOL m_bChangeTime;

	CString m_strWinText;
	int m_nDlgStatus;

	CStringArray m_sarrMessage;
	CStringArray m_sarrText;

};
